{include file="admin/header.tpl" title="header" }
<script src="{$baseurl}/javascript/daily_sale.js"></script>

<div id="hidden_bill_row" style="display:none">
<div>
    <input maxlength="10" type="text" name="bill_paid[]" value="{$post.bill_paid}" style="width:80px" onkeypress="return intOnly(this,event);"  /> 
     <select name="company_id[]" style="width:150px;">
        <option value=""> select company </option>
        {foreach from=$companies item=row}
           <option  {if $post.company_id eq $row.company_id} selected="selected" {/if} value="{$row.company_id}" >{$row.company_name}</option>
        {/foreach}
     </select> <a href="#" onclick="removeBillRow(this)">Remove</a> 
     </div>
</div>             

<div id="content"> {php} echo display_msg(); {/php}
  <div class="error" id="main_error_div" style="display:none;"></div>
  
  {if !isset($post.monthly_expense_id) }
  <h2>Add Monthly Sale</h2>
  <div class="lstable2">
    <form method="post" onsubmit="return formValidate('add');">
      <input type="hidden" name="action" id="action" value="{$post.action}">
      <table width="80%" border="0" cellspacing="0" cellpadding="4">
       <tr>
          <td width="20%" align="left" valign="middle"><strong>Super Mercado :</strong></td>
          <td width="70%" align="left" valign="middle">
            <select name="store_id" style="width:100px;">
            	<option value=""> - select - </option> 
                {foreach from=$stores item=row}
                    <option value="{$row.store_id}"> {$row.store_name} </option> 
                {/foreach}
            </select>
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Month : <span class="mandatory">*</span></strong></td>
          <td width="70%" align="left" valign="middle">
          
          <select name="month" style="width:100px;">
            	<option value=""> - select - </option> 
                {foreach from=$month_array item=row}
                    <option value="{$row.date}"> {$row.name} </option> 
                {/foreach}
            </select>
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Diario Total :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" id="total_sale" name="total_sale" style="width:80px" onkeypress="return intOnly(this,event);" /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Factura Pagado :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10"  type="text" name="total_bill" id="total_bill" style="width:80px" onkeyup="updateTotal();"  value="{$post.sale_cash}" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
        {foreach from=$expenses_types item=row}
        <tr>
          <td width="20%" align="left" valign="top"><strong> {$row.expense_name}</strong></td>
          <td width="70%" align="left" valign="top"> 
         	<input class="" maxlength="10" type="text" id="expense_paid_{$row.expense_id}" name="expense_paid[]"  style="width:80px" onkeyup="updateTotal();" onkeypress="return intOnly(this,event);"  /> 
            <input type="hidden" name="expense_id[]" value="{$row.expense_id}"  /> &nbsp; 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        {/foreach}
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Cash Left :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="cash_left" id="cash_left"  style="width:80px"   /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td  colspan="2" align="left"><input name="submit" class="btncss" type="submit" value="Save" />
            &nbsp;
            <input class="btncss" type="button" onclick="location.href='{$baseurl}/admin/monthly_expense.php'" value="Cancel" /></td>
        </tr>
      </table>
    </form>
  </div>
  {else}
   <h2>Edit Monthly Sale</h2>
  <div class="lstable2">
    
    
    <form method="post" onsubmit="return formValidate('update');">
      <input type="hidden" name="action" id="action" value="{$post.action}">
      <input type="hidden" name="monthly_expense_id" id="monthly_expense_id" value="{$post.monthly_expense_id}">
      <table width="80%" border="0" cellspacing="0" cellpadding="4">
      
       <tr>
          <td width="20%" align="left" valign="middle"><strong>Super Mercado :</strong></td>
          <td width="70%" align="left" valign="middle">
            <select name="store_id" style="width:100px;">
            	<option value=""> - select - </option> 
                {foreach from=$stores item=row}
                    <option {if $monthly_expense.store_id eq $row.store_id} selected="selected" {/if} value="{$row.store_id}"> {$row.store_name} </option> 
                {/foreach}
            </select>
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Month : <span class="mandatory">*</span></strong></td>
          <td width="70%" align="left" valign="middle">
          
          <select name="month" style="width:100px;">
            	<option value=""> - select - </option> 
                {foreach from=$month_array item=row}
                    <option  {if $monthly_expense.expense_date eq $row.date} selected="selected" {/if} value="{$row.date}"> {$row.name} </option> 
                {/foreach}
            </select>
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Diario Total :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" id="total_sale" name="total_sale" value="{$monthly_expense.total_sale}" style="width:80px" onkeypress="return intOnly(this,event);" /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Factura Pagado :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10"  type="text" name="total_bill" id="total_bill"  value="{$monthly_expense.total_bill}" style="width:80px" onkeyup="updateTotal();" onkeypress="return intOnly(this,event);"  /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        
        {foreach from=$expenses_types item=row}
        <tr>
          <td width="20%" align="left" valign="top"><strong> {$row.expense_name}</strong></td>
          <td width="70%" align="left" valign="top"> 
         	<input class="" maxlength="10" type="text"  value="{$row.expense_paid}" id="expense_paid_{$row.expense_id}" name="expense_paid[]"  style="width:80px" onkeyup="updateTotal();" onkeypress="return intOnly(this,event);"  /> 
            <input type="hidden" name="expense_id[]" value="{$row.expense_id}"  /> &nbsp; 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        {/foreach}
        <tr>
          <td width="20%" align="left" valign="middle"><strong>Cash Left :</strong></td>
          <td width="70%" align="left" valign="middle">
          	<input maxlength="10" type="text" name="cash_left" id="cash_left"  style="width:80px" /> 
          </td>
          <td width="10%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td  colspan="2" align="left"><input name="submit" class="btncss" type="submit" value="Save" />
            &nbsp;
            <input class="btncss" type="button" onclick="location.href='{$baseurl}/admin/monthly_expense.php'" value="Cancel" /></td>
        </tr>
      </table>
    </form>
    
  </div>
  			
        
         <script language="javascript">
			current_day = '{$smarty.now|date_format:"%d"}';
			current_month = '{$smarty.now|date_format:"%m"}';
			current_year = '{$smarty.now|date_format:"%Y"}';
		 {literal}
                  $('#sale_date').datepicker({minDate: new Date(1970, 1 - 1, 26),
			maxDate: new Date(current_year, current_month - 1, current_day)});
		{/literal}	
        </script>
  		 
  
  {/if} 
  </div>
{include file="admin/footer.tpl" title="footer"} 